﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MemDBAPI;

namespace NICY
{
    public class ODB
    {
        private Configuration config;
        
        private Converter saveConverter = new SaveConverter();

        private Converter queryConverter = new QueryConverter();
        
        private Executor executor;

        private Validator validator = new NameValidator();

        private SQLConnection conn = new SQLConnection();

        public ODB(Configuration config){
            conn.ConnectString = config.getConnStr();
            conn.Open();
        }


        public Boolean save(Object obj){
            Boolean isValid = validator.isValid(obj);
            if(!isValid){
                return false;
            }

            saveConverter.setObject(obj);
            saveConverter.convert();
            List<String> statements = saveConverter.convert();

            executor = new Executor(statements, conn);

            executor.execute();

            return executor.getSaveResult();
        }
  
        public Boolean update(Object obj){
            return true;
        }

        public ResultDataSet query(String queryStr){
            return null;
        }
    }
}
